﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AMDb;
using HtmlAgilityPack;

namespace AMDb.Test
{
    public partial class Form1 : Form
    {
            SearchResult sr = new SearchResult();
            List<Result> lSearchResult = new List<Result>();
            MovieInfo mi = new MovieInfo();

            public Form1()
            {
                InitializeComponent();
            }

            private void bSearch_Click(object sender, EventArgs e)
            {
                lvSearchResult.Items.Clear();
                ilTinyPosters.Images.Clear();
                sr.Keyword = tbKeyword.Text;
                lSearchResult = sr.getSearchResult();

                foreach (Result movie in lSearchResult)
                {
                    ilTinyPosters.Images.Add(movie.PosterIcon);
                    lvSearchResult.Items.Add(new ListViewItem(movie.Title, ilTinyPosters.Images.Count - 1));
                }
            }

            private void lvSearchResult_SelectedIndexChanged(object sender, EventArgs e)
            {

                lvMovieInfo.Items.Clear();
                lDescription.Text = "";
                mi.Url = lSearchResult[lvSearchResult.FocusedItem.Index].Url;
                var m = mi.getMovieInfo();
                pbPoster.Image = m.Poster;
                lvMovieInfo.Items.Add("Title").SubItems.Add(m.Title);
                lvMovieInfo.Items.Add("Year").SubItems.Add(m.Year);
                lvMovieInfo.Items.Add("Meter Rank").SubItems.Add(m.MeterRank);
                lvMovieInfo.Items.Add("Popularity").SubItems.Add(m.Popularity);
                lvMovieInfo.Items.Add("Meter Change").SubItems.Add(m.MeterChange);
                lvMovieInfo.Items.Add("Genre").SubItems.Add(m.Genre);
                lvMovieInfo.Items.Add("Content Rating").SubItems.Add(m.ContentRating);
                lvMovieInfo.Items.Add("Release Date").SubItems.Add(m.ReleaseDate);
                lvMovieInfo.Items.Add("Rating").SubItems.Add(m.Rating);
                lvMovieInfo.Items.Add("Votes").SubItems.Add(m.Votes);
                lvMovieInfo.Items.Add("Metascore").SubItems.Add(m.Metascore);
                lvMovieInfo.Items.Add("Metacritic").SubItems.Add(m.Metacritic);
                lvMovieInfo.Items.Add("User Reviews").SubItems.Add(m.UserReviews);
                lvMovieInfo.Items.Add("Critic Reviews").SubItems.Add(m.CriticReviews);
                lvMovieInfo.Items.Add("Duration").SubItems.Add(m.Duration);
                lvMovieInfo.Items.Add("Director").SubItems.Add(m.Director);
                lvMovieInfo.Items.Add("Writers").SubItems.Add(m.Writers);
                lvMovieInfo.Items.Add("Stars").SubItems.Add(m.Stars);
                lvMovieInfo.Items.Add("Awards").SubItems.Add(m.Awards);
                lDescription.Text += m.Description;
            }
        }
    }
